package com.example.provider;

import com.example.api.bean.Book;
import com.example.api.service.BookService;
import com.example.provider.qiniuyun.IFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

@SpringBootApplication
@Controller
public class ProviderApplication {

    String name="修改后的书籍";
    @Autowired
    IFileService iFileService;

   @Autowired
    BookService bookService;

    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }

    @RequestMapping("transaction_update")
    @Transactional//springboot 的事务是声明式aop的事务，对代码的侵入少，但是默认只拦截运行时异常，可通过rollbackfor来指定生效的异常
    public String updateAll() throws Exception {
        Book book = new Book();
        book.setBook_id(1);
        book.setAuthor(name);
        book.setDescri(name);
        book.setBook_name(name);
        book.setPrice(12);

        bookService.updateBook(book);

        Book book1 = new Book();
        book1.setBook_id(2);
        book1.setAuthor(name);
        book1.setDescri(name);
        book1.setBook_name(name);
        book1.setPrice(12);

        bookService.updateBook(book1);
        throw new Exception("测试可查异常的事务");

    }

    @RequestMapping("1")
    public String upload(){
       return iFileService.getUploadToken().getData();
    }


}

